<?php
namespace Sys\Controller;
use Think\Controller;
class LoginController extends BaseController {
	public function login(){
		$this->display();
	}
	public function doLogin(){
		$where = [
			'mtel' => I('post.mtel'),
			'pwd' => I('post.pwd'),
            'role'=>I('post.role'),
		];
        /*dump($where);exit;*/
        $res=(I('post.role')==1)?teachers:students;
        $member = M($res)
                -> join('__ROLES__ ON __'.strtoupper($res).'__.role = __ROLES__.role_id')
                -> where($where)
                -> find();
		if($member == false){
			$this-> error('登入失败',U('login'));
		}else{
			session('tname',$member['tname']);
			session('sname',$member['sname']);
			session('role',$member['menu_ids']);
			$this-> success('登入成功',U('Student/index'));
		}

	}
    public function loginout(){
        session(null);
        $this-> success('再见',U('Index/index'));
    }
}